<?php echo $this->render('layouts/__header.phtml'); ?>
<?php echo $this->render('layouts/__nav.phtml'); ?>

<link rel="stylesheet" type="text/css" href="/css/task.css" />
<script type="text/javascript" src="/js/base.js"></script>
<script type="text/javascript">
var opentask = function(taskId, isOpen) {
	var request_uri = '<?php echo $this->this_url;?>?ajax=1&t='+(new Date()).getTime();
	new Ajax(request_uri, {
		method: 'get',
		evalScripts : true,
		data: Object.toQueryString({
			ti: taskId,
			io: isOpen
		}),
		update: 'tasklistbox'
	}).request();
}
var viewtask = function(taskId) {
	var request_uri = '<?php echo $this->this_url;?>?ajax=1&t='+(new Date()).getTime();
	PopBox.pop('loading ...', {loading:true});
	new Ajax(request_uri, {
		method: 'get',
		evalScripts : true,
		data: Object.toQueryString({
			fn: 'view',
			ti: taskId
		}),
		onComplete: function(){
			PopBox.pop(this.response.text);
		}
	}).request();
}
var marktask = function(taskId) {
	var request_uri = '<?php echo $this->this_url;?>?ajax=1&t='+(new Date()).getTime();
	PopBox.pop('loading ...', {loading:true});
	new Ajax(request_uri, {
		method: 'get',
		evalScripts : true,
		data: Object.toQueryString({
			fn: 'mark',
			ti: taskId
		}),
		onComplete: function(){
			PopBox.pop(this.response.text);
		}
	}).request();
}
window.addEvent('domready', function(){
	$('gopagebtn').addEvent('click', function(e){
		e = new Event(e);
		var page_to = parseInt($('pageto').value);
		var page_num = (page_to > 1) ? $('pageto').value : 1;
		var page_url = '<?php echo $this->base_url;?>finish/p/'+page_num;
		redirect(page_url);
		e.stop();
		
	});

	/////////////////////////////////////////////////////
	// search select from
	var request_uri = '<?php echo $this->filter_url;?>?finished=1&t='+(new Date()).getTime();
	['task_status','task_prior','property_id','request_id','manager_id','developer_id'].each(function(item, index){
		$(item).addEvent('change', function(e){
			$('loadingbox').setStyle('display', 'block');
			new Ajax(request_uri, {
				method: 'get',
				data: Object.toQueryString({
					k: item,
					v: $(item).value
				}),
				onComplete: function(){
					if ('success' == this.response.text) {
						redirect('<?php echo $this->finish_url;?>');
					}
				}
			}).request();
		});
	});
	['title'].each(function(item, index){
		$(item).addEvent('keyup', function(e){
			var event = new Event(e);
			if (event.key == 'enter') {
				$('loadingbox').setStyle('display', 'block');
				new Ajax(request_uri, {
					method: 'get',
					data: Object.toQueryString({
						k: item,
						v: $(item).value
					}),
					onComplete: function(){
						if ('success' == this.response.text) {
							redirect('<?php echo $this->finish_url;?>');
						}
					}
				}).request();
			}
			event.stop();
		});
	});
});
</script>

		<h1>Completed Task List</h1>
		
		<div id="tasklistbox">
	    <table class="normaltable">
			<tr class="selectarea">
				<td></td>
				<td></td>
				<td></td>
				<td><?php echo $this->formSelect('task_status', $this->filter['task_status'], null, $this->entites['status']) ?></td>
				<td><?php echo $this->formSelect('task_prior', $this->filter['task_prior'], null, $this->entites['prior']) ?></td>
				<td><?php echo $this->formSelect('property_id', $this->filter['property_id'], null, $this->entites['property']) ?></td>
				<td class="title"><input id="title" name="title" type="text" class="title" value="<?php echo $this->filter['title']?>" /></td>
				<td><?php echo $this->formSelect('request_id', $this->filter['request_id'], null, $this->entites['requester']) ?></td>
				<td><?php echo $this->formSelect('manager_id', $this->filter['manager_id'], null, $this->entites['manager']) ?></td>
				<td><?php echo $this->formSelect('developer_id', $this->filter['developer_id'], null, $this->entites['engineer']) ?></td>
				<td colspan="2" class="sub" style="text-align:right;font-size:10pt;font-weight:bold;color:blue">
				We Get <?php echo $this->sum; ?>
				</td>
			</tr>		
			<tr class="tit">
			  <td></td>
					<td>ID</td>
					<td class="attachment"><img src="/images/icon_attach.gif"/></td>
					<td>Status</td>
					<td>Prior</td>
					<td>Property</td>
					<td class="title">Title</td>
					<td>Requester</td>
					<td>PM</td>
					<td>Assign to</td>
					<td>Launch Day</td>
					<td>Mark</td>
			</tr>
			<?php if ($this->task_content == ''): ?>
				<tr><td colspan="13" style="color:#cc0000;height:50px;"><b>Empty Task List ...</b></td></tr>
			<?php else: ?>
				<?php echo $this->task_content; ?>
			<?php endif; ?>
		</table>
		</div>
		
		<div class="taskcolorlist divbtm">
			<table class="taskcolortable"><tr>
			<?php $level = 1; ?>
			<?php foreach ($this->bg_color as $color): ?>
				<td style="height:20px;width:20px;border:1px solid #999;background:<?php echo $color; ?>">&nbsp;</td><td>Level <?php echo $level; ?></td><td>&nbsp;</td>
				<?php $level++; ?>
			<?php endforeach; ?>
			<td style="height:20px;width:20px;text-align:center"><img src="/images/btn_leaf.gif"/></td><td>Leaf Task</td>
			</tr></table>
		</div>
		
		<div class="listbottom">
			<div class="pagelist" <?php if (!$this->pager) {echo 'style="display:none"';} ?> >
			<b>Task&nbsp;<?php echo intval($this->pager['frNum'] + 1);?>&nbsp;~&nbsp;<?php echo intval($this->pager['toNum']);?>&nbsp;Total (<?php echo intval($this->pager['totalNum']);?>)</b>&nbsp;
			<?php echo $this->pager['prevStr'];?>&nbsp;<?php echo $this->pager['pageStr'];?>&nbsp;<?php echo $this->pager['nextStr'];?>&nbsp;<input id="pageto" type="text" /><a id="gopagebtn" href="javascript:;">Go</a>
			</div>
		</div>

		<div id="loadingbox" style="display:none;padding:2px 0px 0px 8px;width:125px;height:20px;text-align:center;position:absolute;top:0px;right:0px;background:#CC0000;color:#fff;z-index:10000;"><b>Loading ...</b></div>

<?php echo $this->render('layouts/__footer.phtml'); ?>